/* 
    练习1
*/

const fp = require('lodash/fp')
const { Maybe,Container } = require('./support')

let maybe = Maybe.of([5,6,1])
let ex1 = () => {
    return maybe.map( x => fp.map(fp.add(1),x))
}
console.log('练习题一结果',ex1());// 练习题一结果 Maybe { _value: [ 6, 7, 2 ] }

/* 
    练习2
*/
let xs = Container.of(['do','ray','me','fa','so','la','ti','do'])
let ex2 = () => {
    return xs.map( x => fp.first(x)) // 练习题二结果 Container { _value: 'do' } 
}
console.log('练习题二结果',ex2());

/* 
    练习3
*/
let safeProp = fp.curry(function(x,o){
    return Maybe.of(o[x])
})
let user = {id:2,name:'Albert'}
let ex3 = (data) => {
    return fp.flowRight(fp.map(fp.first),safeProp('name'))(data)
}
console.log('练习题三结果',ex3(user)); // 练习题三结果 [ 'A' ]

/* 
    练习4
*/
// let ex4 = function(n){
//     if(n){
//         return parseInt(n)
//     }
// }

let ex4 = n => Maybe.of(n).map( x => parseInt(x))